package cn.huanglei936.essay.itext;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

public class MyFileVisitor extends SimpleFileVisitor<Path> {

    /**
     * Invoked for a file in a directory.
     *
     * <p> Unless overridden, this method returns {@link FileVisitResult#CONTINUE
     * CONTINUE}.
     *
     * @param file
     * @param attrs
     */
    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        File file1 = file.toFile();
        String fileName = file1.getName();

        String rootPath = "C:\\Projects\\infomass\\matmass new\\back\\autostandard\\pdfs\\";
        File originFile = new File(rootPath + fileName);
        if (originFile.exists()) {
            long targetFileLen = file1.length();
            long originFileLen = originFile.length();
            if (targetFileLen != originFileLen) {
                System.out.println("file.getFileName() = " + file1.getAbsolutePath());
                String newFile = file1.getParent() + "\\new" + fileName;
                FileUtils.copyFile(originFile, new File(newFile));
            }
        }
//        else {
//            System.out.println("file no exists = " + file1.getAbsolutePath());
//        }

        return super.visitFile(file, attrs);
    }
}
